﻿using System;
using System.Collections.Generic;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media.Imaging;
using Avalonia.Platform;

namespace LiveHub.AvaloniaApp.Models;

public class MessageBoolConverter : IMultiValueConverter
{
    public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
    {
        if (values.Count != 2) return false;

        if (values[0] is not string model ||
            values[1] is not string messageUserId)
            return false;

        return model == messageUserId;
    }
}

public class MessageNotBoolConverter : IMultiValueConverter
{
    public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
    {
        if (values.Count != 2) return false;

        if (values[0] is not string model ||
            values[1] is not string messageUserId)
            return false;

        return model != messageUserId;
    }
}

public class UserImageConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is string gender)
            return new Bitmap(AssetLoader.Open(new Uri($"avares://LiveHub.AvaloniaApp/Assets/{gender}生.png")));

        return value;
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
        => value;
}